- commit = @repository.commit(branch.target)
- bar_graph_width_factor = @max_commits > 0 ? 100.0/@max_commits : 0
- diverging_commit_counts = @repository.diverging_commit_counts(branch)
- number_commits_behind = diverging_commit_counts[:behind]
- number_commits_ahead = diverging_commit_counts[:ahead]
%li(class="js-branch-#{branch.name}")
  %div
    = link_to namespace_project_tree_path(@project.namespace, @project, branch.name) do
      %span.item-title.str-truncated= branch.name
    &nbsp;
    - if branch.name == @repository.root_ref
      %span.label.label-primary default
    - elsif @repository.merged_to_root_ref? branch.name
      %span.label.label-info.has-tooltip(title="Merged into #{@repository.root_ref}")
        merged

    - if @project.protected_branch? branch.name
      %span.label.label-success
        = icon('lock')
        protected

    - if @project.mirror_ever_updated_successfully? && @repository.diverged_from_upstream?(branch.name)
      %span.label.label-danger.has-tooltip{data: { html: "true", title: branch_diverged_tooltip_message }}
        = icon('exclamation-triangle')
        diverged from upstream

    .controls.hidden-xs
      - if create_mr_button?(@repository.root_ref, branch.name)
        = link_to create_mr_path(@repository.root_ref, branch.name), class: 'btn btn-grouped btn-xs' do
          Merge Request

      - if branch.name != @repository.root_ref
        = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: branch.name), class: 'btn btn-grouped btn-xs', method: :post, title: "Compare" do
          Compare

      - if can_remove_branch?(@project, branch.name)
        = link_to namespace_project_branch_path(@project.namespace, @project, branch.name), class: 'btn btn-grouped btn-xs btn-remove remove-row has-tooltip', title: "Delete branch", method: :delete, data: { confirm: "Deleting the '#{branch.name}' branch cannot be undone. Are you sure?", container: 'body' }, remote: true do
          = icon("trash-o")

    - if branch.name != @repository.root_ref
      .divergence-graph{ title: "#{number_commits_ahead} commits ahead, #{number_commits_behind} commits behind #{@repository.root_ref}" }
        .graph-side
          .bar.bar-behind{ style: "width: #{number_commits_behind * bar_graph_width_factor}%" }
          %span.count.count-behind= number_commits_behind
        .graph-separator
        .graph-side
          .bar.bar-ahead{ style: "width: #{number_commits_ahead * bar_graph_width_factor}%" }
          %span.count.count-ahead= number_commits_ahead


  - if commit
    = render 'projects/branches/commit', commit: commit, project: @project
  - else
    %p
      Cant find HEAD commit for this branch
